package grafica.ventanas;

import grafica.controladores.ControladorEmplAsalariado;
import grafica.controladores.ControladorEmplFreelance;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;

import logica.datatypes.DataEmpresa;

public class empleadoAltaFreelance {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="178,38"
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel jLabel5 = null;
	private JLabel jLabel6 = null;
	private JTextField jTextFieldCI = null;
	private JTextField jTextFieldNombre = null;
	private JTextField jTextFieldApellido = null;
	private JTextField jTextFieldEdad = null;
	private JTextField jTextFieldHoras = null;
	private JTextField jTextFieldPrecio = null;
	private JButton jButtonCancelar = null;
	private JButton jButtonAceptar = null;
	private JComboBox jComboBox = null;
	private ControladorEmplFreelance ConEmplFree;
	private DataEmpresa[] Empresas;
	private int [] IdEmpresas;
	private int cant;
	private JLabel jLabelMensajes = null;
	/**
	 * This method initializes jFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	
	public empleadoAltaFreelance(){
		ConEmplFree = new ControladorEmplFreelance(this);			
	}
	
	public void setVisible (boolean b){	
		this.getJFrame().setVisible(b);
	}
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setSize(new Dimension(330, 358));
			jFrame.setTitle("ALTA FUNCIONARIO FREELANCE");
			jFrame.setContentPane(getJContentPane());
			jFrame.setLocationRelativeTo(null);	
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 1;
			gridBagConstraints21.gridy = 8;
			jLabelMensajes = new JLabel();
			jLabelMensajes.setPreferredSize(new Dimension(200, 26));
			jLabelMensajes.setText("");
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints15.gridy = 1;
			gridBagConstraints15.weightx = 1.0;
			gridBagConstraints15.gridx = 1;
			GridBagConstraints gridBagConstraints61 = new GridBagConstraints();
			gridBagConstraints61.gridx = 0;
			gridBagConstraints61.gridy = 7;
			GridBagConstraints gridBagConstraints51 = new GridBagConstraints();
			gridBagConstraints51.gridx = 1;
			gridBagConstraints51.gridy = 7;
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints14.gridy = 6;
			gridBagConstraints14.weightx = 1.0;
			gridBagConstraints14.gridx = 1;
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints13.gridy = 5;
			gridBagConstraints13.weightx = 1.0;
			gridBagConstraints13.gridx = 1;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints12.gridy = 4;
			gridBagConstraints12.weightx = 1.0;
			gridBagConstraints12.gridx = 1;
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints11.gridy = 3;
			gridBagConstraints11.weightx = 1.0;
			gridBagConstraints11.gridx = 1;
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
			gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints10.gridy = 2;
			gridBagConstraints10.weightx = 1.0;
			gridBagConstraints10.gridx = 1;
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints8.gridy = 0;
			gridBagConstraints8.weightx = 1.0;
			gridBagConstraints8.gridx = 1;
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.gridx = 0;
			gridBagConstraints6.gridy = 6;
			gridBagConstraints10.insets = new Insets(10,10,10,10);
			gridBagConstraints8.insets = new Insets(10,10,10,10);
			gridBagConstraints12.insets = new Insets(10,10,0,10);
			gridBagConstraints13.insets = new Insets(10,10,10,10);
			gridBagConstraints61.insets = new Insets(10,10,10,10);
			jLabel6 = new JLabel();
			jLabel6.setText("   Precio Hora");
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.gridx = 0;
			gridBagConstraints5.gridy = 5;
			jLabel5 = new JLabel();
			jLabel5.setText("   Cant. Horas");
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 0;
			gridBagConstraints4.gridy = 4;
			jLabel4 = new JLabel();
			jLabel4.setText("   Edad");
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 0;
			gridBagConstraints3.gridy = 3;
			jLabel3 = new JLabel();
			jLabel3.setText("   Apellido");
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.gridy = 2;
			jLabel2 = new JLabel();
			jLabel2.setText("   Nombre");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.gridy = 1;
			jLabel1 = new JLabel();
			jLabel1.setText("   Empresa");
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jLabel = new JLabel();
			jLabel.setText("   CI");
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(jLabel, gridBagConstraints);
			jPanel.add(jLabel1, gridBagConstraints1);
			jPanel.add(jLabel2, gridBagConstraints2);
			jPanel.add(jLabel3, gridBagConstraints3);
			jPanel.add(jLabel4, gridBagConstraints4);
			jPanel.add(jLabel5, gridBagConstraints5);
			jPanel.add(jLabel6, gridBagConstraints6);
			jPanel.add(getJTextFieldCI(), gridBagConstraints8);
			jPanel.add(getJTextFieldNombre(), gridBagConstraints10);
			jPanel.add(getJTextFieldApellido(), gridBagConstraints11);
			jPanel.add(getJTextFieldEdad(), gridBagConstraints12);
			jPanel.add(getJTextFieldHoras(), gridBagConstraints13);
			jPanel.add(getJTextFieldPrecio(), gridBagConstraints14);
			jPanel.add(getJButtonCancelar(), gridBagConstraints51);
			jPanel.add(getJButtonAceptar(), gridBagConstraints61);
			jPanel.add(getJComboBox(), gridBagConstraints15);
			jPanel.add(jLabelMensajes, gridBagConstraints21);
		}
		return jPanel;
	}

	/**
	 * This method initializes jTextFieldCI	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCI() {
		if (jTextFieldCI == null) {
			jTextFieldCI = new JTextField();
			jTextFieldCI.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldCI;
	}

	/**
	 * This method initializes jTextFieldNombre	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldNombre() {
		if (jTextFieldNombre == null) {
			jTextFieldNombre = new JTextField();
			jTextFieldNombre.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldNombre;
	}

	/**
	 * This method initializes jTextFieldApellido	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldApellido() {
		if (jTextFieldApellido == null) {
			jTextFieldApellido = new JTextField();
			jTextFieldApellido.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldApellido;
	}

	/**
	 * This method initializes jTextFieldEdad	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldEdad() {
		if (jTextFieldEdad == null) {
			jTextFieldEdad = new JTextField();
			jTextFieldEdad.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldEdad;
	}

	/**
	 * This method initializes jTextFieldHoras	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldHoras() {
		if (jTextFieldHoras == null) {
			jTextFieldHoras = new JTextField();
			jTextFieldHoras.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldHoras;
	}

	/**
	 * This method initializes jTextFieldPrecio	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPrecio() {
		if (jTextFieldPrecio == null) {
			jTextFieldPrecio = new JTextField();
			jTextFieldPrecio.setPreferredSize(new java.awt.Dimension(180,25));
		}
		return jTextFieldPrecio;
	}
	/**
	 * This method initializes jButtonCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setText("Cancelar");
			ActionListener BotonCancelar = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 				
					jFrame.dispose();				
				}
			};
			jButtonCancelar.addActionListener(BotonCancelar );
		}
		return jButtonCancelar;
	}
	/**
	 * This method initializes jButtonAceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAceptar() {
		if (jButtonAceptar == null) {
			jButtonAceptar = new JButton();
			jButtonAceptar.setText("Aceptar");
			ActionListener ButtonAceptar = new ActionListener(){
				public void actionPerformed (ActionEvent e){						
					ConEmplFree.AltaEmplFreelance(Integer.parseInt(getJTextFieldCI().getText()), getJTextFieldNombre().getText().toString(), getJTextFieldApellido().getText().toString(), Integer.parseInt(getJTextFieldEdad().getText()), IdEmpresas[jComboBox.getSelectedIndex()], Integer.parseInt(getJTextFieldHoras().getText()),Float.parseFloat(getJTextFieldPrecio().getText()));
					System.out.println("Fin valor");
				}
			};
			jButtonAceptar.addActionListener(ButtonAceptar);
			}
		return jButtonAceptar;
	}
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();	
			jComboBox.setPreferredSize(new Dimension(180, 25));
			////Completra, Cargar empresas existentes en base
			Empresas = ConEmplFree.getEmpreas();
			cant = Empresas.length;
			IdEmpresas = new int[cant];
			
			for (int i=0; i<cant; i++){	
				jComboBox.addItem(Empresas[i].getRazon_Social());	
				IdEmpresas[i] = Empresas[i].getRut();
		   }
			
		
		}
		return jComboBox;
	}
	
	public void setJTextAreaMensajes(String info){
		this.jLabelMensajes.setText(info);
	}
	
	public void limpiarData(){
		this.jTextFieldCI.setText("");
		this.jTextFieldNombre.setText("");
		this.jTextFieldApellido.setText("");
		this.jTextFieldEdad.setText("");
		this.jTextFieldHoras.setText("");
		this.jTextFieldPrecio.setText("");
	}
	
}
